package com.quad.innovators.salesease.converter;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.quad.innovators.salesease.common.result.PageResultBean;
import com.quad.innovators.salesease.model.entity.base.Product;
import com.quad.innovators.salesease.model.form.base.ProductForm;
import com.quad.innovators.salesease.model.vo.base.ProductVO;
import org.mapstruct.InheritInverseConfiguration;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;

/**
 * 对象转换器
 *
 * @author haoxr
 * @since 2022/6/8
 */
@Mapper(componentModel = "spring")
public interface ProductConverter {

    @Mappings({
            @Mapping(target = "items", source = "records"),
            @Mapping(target = "pageInfo.currPage", source = "current"),
            @Mapping(target = "pageInfo.totalCount", source = "total"),
            @Mapping(target = "pageInfo.pageSize", source = "size")
    })
    PageResultBean<ProductVO> toPageVo(Page<ProductVO> bo);

    ProductForm toForm(Product entity);

    @InheritInverseConfiguration(name = "toForm")
    Product toEntity(ProductForm entity);

}
